//
//  MessageServiceProviderChooseCell.m
//  BigToBig
//
//  Created by yi liu on 16/8/15.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "MessageServiceProviderChooseCell.h"


@implementation MessageServiceProviderChooseCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)createView{
    self.firstButton = [[UIButton alloc] init];
    [self.firstButton setImage:[UIImage imageNamed:@"xuanzhong"] forState:UIControlStateSelected];
    [self.firstButton setImage:[UIImage imageNamed:@"weixuanzhong"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.firstButton];
    
    self.firstLabel = [[UILabel alloc] init];
    
    self.firstLabel.textColor = [UIColor lightGrayColor];
    self.firstLabel.font = [UIFont systemFontOfSize:13];
    self.firstLabel.text = @"个人投资";
    [self.contentView addSubview:self.firstLabel];
    
    self.secondButton = [[UIButton alloc] init];
    [self.secondButton setImage:[UIImage imageNamed:@"xuanzhong"] forState:UIControlStateSelected];
    [self.secondButton setImage:[UIImage imageNamed:@"weixuanzhong"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.secondButton];
    
    self.secondLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.secondLabel];
    self.secondLabel.textColor = [UIColor lightGrayColor];
    self.secondLabel.font = [UIFont systemFontOfSize:13];
    self.secondLabel.text = @"机构投资";
    
    [self.firstButton addTarget:self action:@selector(time1:) forControlEvents:UIControlEventTouchUpInside];
    self.firstButton.tag = 1000;
    [self.secondButton addTarget:self action:@selector(time1:) forControlEvents:UIControlEventTouchUpInside];
    self.secondButton.tag = 1001;
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.firstButton.frame = CGRectMake(kScreenWidth - 185, self.contentView.frame.size.height / 2 - 12, 24, 24);
    self.firstLabel.frame = CGRectMake(kScreenWidth - 165, self.contentView.frame.size.height / 2 - 15, 55, 30);
    self.secondButton.frame = CGRectMake(kScreenWidth - 110, self.contentView.frame.size.height / 2 - 12, 24, 24);
    self.secondLabel.frame = CGRectMake(kScreenWidth - 80, self.contentView.frame.size.height / 2 - 15, 55, 30);
    if (self.isSelected == 1000) {
        [self time1:self.firstButton];
    }
    else if(self.isSelected == 1001){
        [self time1:self.secondButton];
    }
}
- (void)time1:(UIButton *)btn{
    
    
    if (self.isSelected == 0) {
        btn.selected = !btn.selected;
        self.isSelected = btn.tag;
    }
    else{
        
        if (btn.tag == self.isSelected) {
            btn.selected = YES;
            return;
        }
        else{
            if (btn.tag == 1000) {
                btn.selected = !btn.selected;
                self.secondButton.selected = !self.secondButton.selected;
                self.isSelected = 1000;
            }
            else{
                btn.selected = !btn.selected;
                self.firstButton.selected = !self.secondButton.selected;
                self.isSelected = 1001;
            }
            
        }
    }
    [self.messageServiceProviderChooseCellDelegate changeSelectedWithSelected:self.isSelected title:self.titleLab.text];
    
    
    
}


@end
